package com.tools.api;

import com.tools.service.CaptchaService;
import com.tools.commons.annotation.AnonymousAccess;
import com.tools.commons.constants.SystemConstants;
import com.tools.commons.exceptions.BadRequestException;
import com.tools.commons.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping(SystemConstants.Api.CAPTCHA)
public class CaptchaController {
    private final CaptchaService captchaService;

    @GetMapping()
    @AnonymousAccess
    public String captcha(String t, String userName) {
        if (StringUtils.isNotBlank(t) && StringUtils.isNotBlank(userName)) {
            String uid = t + userName;
            return captchaService.generator(uid);
        }
        throw new BadRequestException("参数错误");
    }
}
